package jgl.vajra.operator.widget.manager;

import android.view.View;

import com.app.hubert.guide.NewbieGuide;
import com.app.hubert.guide.core.Builder;
import com.app.hubert.guide.core.Controller;
import com.app.hubert.guide.listener.OnGuideChangedListener;
import com.app.hubert.guide.listener.OnLayoutInflatedListener;
import com.app.hubert.guide.model.GuidePage;

import androidx.annotation.LayoutRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

/**
 * Created by Administrator on 2018/12/12.
 */

public class GuideManager {
    private static class GuideManagerSingleton {
        private static final GuideManager INSTANCE = new GuideManager();

    }

    public static GuideManager getInstance() {
        return GuideManager.GuideManagerSingleton.INSTANCE;
    }

    private GuideManager() {
    }

    public void showMainActivityGuide(FragmentActivity activity, View anchor, OnGuideChangedListener listener, View... view) {

        showGuide(activity, "mainActivityGuide", anchor, listener, view);
    }

    public void showMainFragmentGuide(Fragment fragment, View anchor,  View... view) {

        showGuide(fragment, "mainActivityGuide", null, null, view);
    }

    public void showMineActivityGuide(FragmentActivity activity, View anchor, View... view) {

        showGuide(activity, "mineActivityGuide", anchor, view);
    }

    public void showMineFragmentGuide(Fragment fragment, View anchor, View... view) {

        showGuide(fragment, "mineActivityGuide", null, view);
    }

    public void showOrderListActivityGuide(FragmentActivity activity, View anchor, View... view) {

        showGuide(activity, "orderListActivityGuide", anchor, view);
    }

    public void showGoodsDetailsActivityGuide(FragmentActivity activity, View... view) {

        showGuide(activity, "goodsDetailsActivityGuide", null, view);
    }

    public void showShoppingCartActivityGuide(FragmentActivity activity, View... view) {

        showGuide(activity, "shoppingCartActivity", null, view);
    }

    public void showShoppingCartFragmentGuide(Fragment fragment, View... view) {

        showGuide(fragment, "shoppingCartActivity", null, view);
    }

    public void showOrderConfirmActivityGuide(FragmentActivity activity, View... view) {

        showGuide(activity, "showOrderConfirmActivityGuide", null, view);
    }

    public void showGoodDetailsFragmentGuide(Fragment fragment, View... view) {
        showGuide(fragment, "mainActivityGuide", view);
    }

    public void showGuide(FragmentActivity activity, String label, View anchor, final View... view) {


        showGuide(activity, label, anchor, null, view);
    }

    public void showGuide(Fragment activity, String label, View anchor, final View... view) {


        showGuide(activity, label, anchor, null, view);
    }

    public void showGuide(FragmentActivity activity, String label, View anchor, OnGuideChangedListener listener, final View... view) {

        Builder guideBuilder = NewbieGuide.with(activity)
                .setLabel(label).alwaysShow(false);
        if (anchor != null)
            guideBuilder.anchor(anchor);
        if (listener != null)
            guideBuilder.setOnGuideChangedListener(listener);
        showGuide(guideBuilder, view);
    }

    public void showGuide(Fragment activity, String label, View anchor, OnGuideChangedListener listener, final View... view) {

        Builder guideBuilder = NewbieGuide.with(activity)
                .setLabel(label).alwaysShow(false);
        if (anchor != null)
            guideBuilder.anchor(anchor);
        if (listener != null)
            guideBuilder.setOnGuideChangedListener(listener);
        showGuide(guideBuilder, view);
    }

    public void showGuide(Fragment activity, String label, View... view) {

        Builder guideBuilder = NewbieGuide.with(activity)
                .setLabel(label).alwaysShow(false);
        showGuide(guideBuilder, view);
    }

    private void showGuide(Builder guideBuilder, View[] view) {
     /*   Animation enterAnimation = new AlphaAnimation(0f, 1f);
        enterAnimation.setDuration(400);
        enterAnimation.setFillAfter(true);
*/
    /*    Animation exitAnimation = new AlphaAnimation(1f, 0f);
        exitAnimation.setDuration(400);
        exitAnimation.setFillAfter(true);*/
        for (View v : view) {
            @LayoutRes int tag = (int) v.getTag();
            GuidePage guidePage = GuidePage.newInstance()

                    .addHighLight(v)
                    .setLayoutRes(tag, null).setOnLayoutInflatedListener(new OnLayoutInflatedListener() {
                        @Override
                        public void onLayoutInflated(View view, Controller controller) {
                            //引导页布局填充后回调，用于初始化
                          /*  ImageView iv = view.findViewById(R.id.iv_arrow);
                            if (iv != null) {
                                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) iv.getLayoutParams();
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    params.topMargin += DisplayUtils.getStatusBarHeight(UIUtils.getContext());
                                    iv.setLayoutParams(params);
                                }
                            }*/
                        }
                    });
            //进入动画
            //     .setEnterAnimation(enterAnimation);
            //退出动画
            //.setExitAnimation(exitAnimation);
            guidePage.setEverywhereCancelable(false);
            guideBuilder.addGuidePage(guidePage);


        }


        guideBuilder.show();
    }
}
